"""Input validation utilities for PolyModel Agent"""

from typing import Any, Dict, List, Optional
from modules.base.exceptions import InvalidInputError

def validate_text_input(text: str, min_length: int = 1, max_length: int = 1000) -> bool:
    """
    Validate text input.
    
    Args:
        text (str): Input text to validate
        min_length (int): Minimum allowed length
        max_length (int): Maximum allowed length
        
    Returns:
        bool: True if input is valid
        
    Raises:
        InvalidInputError: If validation fails
    """
    if not isinstance(text, str):
        raise InvalidInputError("Input must be a string")
    
    if not min_length <= len(text) <= max_length:
        raise InvalidInputError(
            f"Text length must be between {min_length} and {max_length} characters"
        )
    
    return True

def validate_model_config(config: Dict[str, Any]) -> bool:
    """
    Validate model configuration.
    
    Args:
        config (Dict[str, Any]): Configuration dictionary
        
    Returns:
        bool: True if configuration is valid
        
    Raises:
        InvalidInputError: If validation fails
    """
    required_fields = ["model_name", "parameters"]
    
    for field in required_fields:
        if field not in config:
            raise InvalidInputError(f"Missing required field: {field}")
    
    return True

def validate_api_key(api_key: Optional[str]) -> bool:
    """
    Validate API key format.
    
    Args:
        api_key (Optional[str]): API key to validate
        
    Returns:
        bool: True if API key is valid
        
    Raises:
        InvalidInputError: If validation fails
    """
    if api_key is None:
        raise InvalidInputError("API key is required")
    
    if not isinstance(api_key, str) or len(api_key) < 8:
        raise InvalidInputError("Invalid API key format")
    
    return True
